# _*_ coding: utf8
"""
author: ning.luo
create_date: 2019/12/12
last_update: 2019/12/12
"""

import requests
import json

class ReturnFee():
    '''退费管理接口'''

    def __init__(self):
        self.base_url = "http://test-api.intra.casstime.com/merchant-service"
        self.headers = {'Content-Type': 'application/json'}

    def setup_class(self):
        pass

    def teardown_class(self):
        pass

    def query_refund_info(self, **body_data):
        '''查询退费详情'''
        url = self.base_url + "/offline/refund"
        response = requests.post(url, data=json.dumps(body_data), headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("查询退费详情！")

    def query_refund_by_storeId(self, **params):
        '''退费详情查询根据店铺id'''
        url = self.base_url + "/offline/refundinfo/bystoreid"
        response = requests.get(url, params)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("退费详情查询根据店铺id！")

    def divide_pages_query_refund(self, **params):
        '''分页查询退费管理列表'''
        url = self.base_url + "/offline/v1/queryOfflineRefund"
        response = requests.get(url, params=params, headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("分页查询退费管理列表！")

    def initialization_refund_fee(self, **body_data):
        '''初始化、更新退费管理'''
        url = self.base_url + "/offline/v1/refund/save"
        response =requests.post(url, data=json.dumps(body_data), headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("分页查询退费管理列表！")



if __name__ == "__main__":
    re = ReturnFee()
    body_refund = {
        "companyId": "string",
        "createdBy": "string",
        "createdName": "string",
        "createdTime": "2019-12-12T06:45:03.612Z",
        "deductAmount": 0,
        "deductReason": "string",
        "guaranteeAmount": 0,
        "guaranteeId": "string",
        "offlineType": "string",
        "refundAmount": 0,
        "refundStatus": "string",
        "refundTime": "2019-12-12T06:45:03.612Z",
        "storeId": "string",
        "storeName": "string"
    }
    params_refund = {
        "storeId": "string"
    }
    params_pages = {
        "storeId": "",
        "offlineType": "",
        "offlineRefundStatus": "",
        "customerManager": "",
        "pageNo": "",
        "pageSize":""
    }
    body_init = {
        "cityName": "string",
        "customerManager": "string",
        "offlineRefundStatus": "TO_BE_CONFIRMED",
        "offlineType": "MERCHANT_APPLICATION",
        "storeId": "string",
        "storeName": "string"
    }

    # 退费详情查询
    re.query_refund_info(**body_refund)

    # 退费详情查询根据店铺id
    re.query_refund_by_storeId(**params_refund)

    # 分页查询退费管理列表
    re.divide_pages_query_refund(**params_pages)

    # 初始化、更新退费管理
    re.initialization_refund_fee(**body_init)
